home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / giglio / testlib.cpp < prev   
C/C++ Source or Header  |  1995-07-09  |  2KB  |  101 lines

  1. Listing 2
  2.  
  3. #include <windows.h>
  4.  
  5. static char *msg_title = "EntryPoint";
  6.  
  7. // First DLL function
  8. long MessA(HWND hWnd, int num, LPSTR name)
  9. {
  10.   char buf[80];
  11.   wsprintf(buf, "MessA: num = %d, name = %s", num, name);
  12.   MessageBox(hWnd, buf, msg_title, MB_OK);
  13.   return('A');
  14. }
  15.  
  16. // Second DLL function
  17. int MessB(HWND hWnd, LPSTR name, char ch, long blah)
  18. {
  19.   char buf[80];
  20.   wsprintf(buf, "MessB: name = %s, ch = %c, blah = %lx",
  21.            name, ch, blah);
  22.   MessageBox(hWnd, buf, msg_title, MB_OK);
  23.   return('B');
  24. }
  25.  
  26. // Third DLL function
  27. int MessC(HWND hWnd, char ch)
  28. {
  29.   char buf[80];
  30.   wsprintf(buf, "MessC: ch = %c", ch);
  31.   MessageBox(hWnd, buf, msg_title, MB_OK);
  32.   return('C');
  33. }
  34.  
  35. // Fourth DLL function
  36. LPSTR MessD(HWND hWnd, LPSTR str)
  37. {
  38.   char buf[80];
  39.   wsprintf(buf, "MessD: str = %s", str);
  40.   MessageBox(hWnd, buf, msg_title, MB_OK);
  41.   return(str);
  42. }
  43.  
  44. #define BUILD_FUNCTION_ARRAY
  45. #include "testenum.h"        // Defines fxn pointer array
  46.  
  47. // Must be extern "C" so name isn't mangled
  48. extern "C" {
  49.  
  50. // Entry Point Function
  51. void FAR _export Entry(void)
  52. {
  53.   // The following variables must be static
  54.   // They CANNOT be on the stack, nor can any
  55.   // automatic variables be defined.
  56.   static short hold_ds;
  57.   static short hold_bp;      // bp may not be needed
  58.   static short hold_ip;      // depending on optimizations
  59.   static short hold_cs;
  60.   static short func_id;
  61.  
  62.   // Pop everything down to the
  63.   // DLL function's argument list
  64.   asm {
  65.     pop hold_ds;
  66.     pop hold_bp;
  67.     pop hold_ip;
  68.     pop hold_cs;
  69.     pop func_id;
  70.   }
  71.  
  72.   // Call the DLL function
  73.   (pFunc[func_id])();
  74.  
  75.   // Restore the stack so the entry point
  76.   // function can return correctly
  77.   asm {
  78.     push func_id;
  79.     push hold_cs;
  80.     push hold_ip;
  81.     push hold_bp;
  82.     push hold_ds;
  83.   }
  84. }
  85.  
  86. }  // extern "C"
  87.  
  88.  
  89. // The LibMain and WEP functions that follow are necessary
  90. //  to initalize and shutdown the DLL.
  91. int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg,
  92.                        WORD cbHeapSize, LPSTR lpszCmdLine)
  93. {
  94.   return LocalInit(wDataSeg, NULL, cbHeapSize);
  95. }
  96.  
  97. int FAR PASCAL WEP(int nParameter)
  98. {
  99.   return TRUE;
  100. }
  101.